﻿CREATE proc phannhommenu_themmenu      
@MaNhom int,      
@MenuID int,      
@Cap int,      
@MenuCha int   ,  
@Command int  
as      
if exists(select * from QuanTri_PhanNhomMenu Where MenuID =@MenuID and MaNhomMenuND =@MaNhom)      
begin      
select ErrCode=0      
end      
else      
begin      
insert into QuanTri_PhanNhomMenu(MenuID,Cap,MenuCha,MaNhomMenuND,Quyen_CapNhat,Quyen_Xem,Quyen_Xoa,ThuTuXuatHien,IDCN)      
values(@MenuID,@Cap,@MenuCha,@MaNhom,0,0,0,0,@Command)    
declare @IDPhanNhomMenu as int
select @IDPhanNhomMenu=@@IDENTITY
insert into QuanTri_EditUserRoleInGroup (IDPhanNhomNguoiDung,IDCapQuyen,IDPhanNhomMenu,Quyen_CapNhat,Quyen_Xem,Quyen_Xoa)  
select distinct e.ID as IDPhanNhomNguoiDung, a.ID as IDCapQuyen,c.ID as IDPhanNhomMenu,c.Quyen_CapNhat,c.Quyen_Xem,c.Quyen_Xoa
from QuanTri_CapQuyenNguoiDungSuDungMenu a,DanhMuc_NhomMenuNguoiDung b,QuanTri_PhanNhomMenu c,
DanhMuc_NhomNguoiDung d ,QuanTri_PhanNhomNguoiDung e
Where a.MaNhomMenuND=b.MaNhomMenuND and b.MaNhomMenuND=c.MaNhomMenuND and a.MaNhomUser=d.MaNhomUser and d.MaNhomUser=e.MaNhomUser
and c.ID=@IDPhanNhomMenu
select ErrCode=1      
end 